package logobj.ftpUtil.analysis;

import logobj.config.ConfProperties;
import org.apache.commons.net.ftp.FTPClient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class AnalysisFtp {
    public Map<String, ArrayList> startFtp(){
        //获取配置
        AnalysisFtpConfig analysisFtpConfig = new AnalysisFtpConfig(ConfProperties.ftp_ip,ConfProperties.ftp_port,ConfProperties.ftp_username,ConfProperties.ftp_pwd);
        AnalysisFtpUtilBase analysisFtpUtilBase = new AnalysisFtpUtilBase();
        //获取客户端连接
        FTPClient ftpClient = analysisFtpUtilBase.connectClient(analysisFtpConfig);
        //获取文件列表信息
        Map<String , ArrayList> ftpFileinfo = analysisFtpUtilBase.getFtpFileNameSize(ftpClient);
        ArrayList namelist1 = ftpFileinfo.get("namelist");
        ArrayList sizelist1 = ftpFileinfo.get("sizelist");
        ArrayList namelist = new ArrayList();
        ArrayList sizelist = new ArrayList();
        String filename ="";
        for(int i = 0;i<namelist1.size();i++){
            filename = String.valueOf(namelist1.get(i));
            if(filename.indexOf(".log") != -1){
                analysisFtpUtilBase.download(ftpClient, ConfProperties.ftp_path, filename , ConfProperties.ftp_localpath, filename );
                namelist.add(namelist1.get(i));
                sizelist.add(sizelist1.get(i));
            }
        }
        Map<String,ArrayList> fineinfomap = new HashMap<>();
        fineinfomap.put("namelist",namelist);
        fineinfomap.put("sizelist",sizelist);

        //删除文件
       // analysisFtpUtilBase.deleteFile(ftpClient,ConfProperties.ftp_path,namelist);
        //关闭tfp
        analysisFtpUtilBase.disconnect(ftpClient);
        return fineinfomap;
    }
}
